    program clean_fees
      character*200 raw
      character*6 ticker,tickets
      character*8 date,astid
      character*9 cusip
      character*1 contr,loanty,coll
      character*14 value,units
      character*11 age,lavg,lmax,lmin,lstd
      dimension ic(16)
      open(unit=10,file='e:\FIS\H_P5_20140101_20140331_rep.txt')
      open(unit=98,file='e:\FIS\test.txt')
!      open(unit=99,file='e:\FIS\fees_200501_200503.txt')
      open(unit=99,file='e:\FIS\fees_201401_201403_ret_rep.txt')
      read(10,1000)raw
      i=0
1     i=i+1      
      read(10,1000,end=500)raw
!      write(6,1000)raw
1000  format(a200)
      n=0
      nc=0
3     n=n+1
      if(n.lt.201) go to 4
      write(6,6677)
6677  format(1x,'greater than 200')
      go to 1
4     if(raw(n:n).ne.'|') go to 3
      nc=nc+1
      ic(nc)=n
      if(nc.lt.16) go to 3
      if(i.eq.1) go to 1
      it1=ic(3)+1
      it2=ic(3)+2
      if(raw(it1:it1).ne.'U') go to 1
      if(raw(it2:it2).ne.'S') go to 1
      ii=ic(5)+1
      contr=raw(ii:ii)
      if(contr.ne.'A') go to 1
      ii=ic(6)+1
      loanty=raw(ii:ii)
!      if(loanty.ne.'A') go to 1
!      if(loanty.ne.'N') go to 1
      if(loanty.ne.'R') go to 1
      ii=ic(7)+1
      coll=raw(ii:ii)
      if(coll.ne.'A') go to 1
      astid='        '
      ticker='      '
      date='        '
      cusip='         '
      contr=' '
      loanty=' '
      coll=' '
      tickets='      '
      units='              '
      value='              '
      age='           '
      lavg='           '
      lmax='           '
      lmin='           '
      lstd='           '
      iend=ic(1)-1
      k=9
      do 5 ii=iend,1,-1
          k=k-1
5     astid(k:k)=raw(ii:ii)
      ii1=ic(1)+1
      ii4=ic(1)+4
      ii6=ic(1)+6
      ii7=ic(1)+7
      ii9=ic(1)+9
      ii10=ic(1)+10
      
      date(1:4)=raw(ii1:ii4)
      date(5:6)=raw(ii6:ii7)
      date(7:8)=raw(ii9:ii10)
      ibg=ic(2)+1
      iend=ic(2)+9
      k=0
      do 15 ii=ibg,iend
          k=k+1
15    cusip(k:k)=raw(ii:ii)
      ibg=ic(4)+1
      iend=ic(5)-1
      if(ibg.gt.iend) go to 22
      k=0
      do 20 ii=ibg,iend
          k=k+1
          if(k.gt.6) go to 20
          ticker(k:k)=raw(ii:ii)
20    continue
22    ibg=ic(9)+1
      iend=ic(10)-1
      k=7
      do 25 ii=iend,ibg,-1
          k=k-1
          tickets(k:k)=raw(ii:ii)
25    continue 
      ibg=ic(10)+1
      iend=ic(11)-1
      id=0
      do 30 ii=ibg,iend
30    if(raw(ii:ii).eq.'.') id=ii
      if(id.eq.0) go to 32
      iend=id-1
32    k=15
      do 35 ii=iend,ibg,-1
          k=k-1
35        units(k:k)=raw(ii:ii)
      ibg=ic(11)+1
      iend=ic(12)-1
      id=0
      do 40 ii=ibg,iend
40    if(raw(ii:ii).eq.'.') id=ii
      if(id.eq.0) go to 42
      iend=id-1
42    k=15
      do 45 ii=iend,ibg,-1
          k=k-1
45    value(k:k)=raw(ii:ii)
      ibg=ic(12)+1
      iend=ic(13)-1
      k=12
      do 50 ii=iend,ibg,-1
          k=k-1
          age(k:k)=raw(ii:ii)
50    continue   
      ibg=ic(13)+1
      iend=ic(14)-1
      k=12
      do 55 ii=iend,ibg,-1
          k=k-1
          lavg(k:k)=raw(ii:ii)
55    continue 
      if(lavg(6:6).eq.'-') lavg(5:6)='-0'
      if(lavg(6:6).eq.' ') lavg(6:6)='0'
      ibg=ic(14)+1
      iend=ic(15)-1
      k=12
      do 60 ii=iend,ibg,-1
          k=k-1
          lmax(k:k)=raw(ii:ii)
60    continue   
      if(lmax(6:6).eq.'-') lmax(5:6)='-0'
      if(lmax(6:6).eq.' ') lmax(6:6)='0'
      ibg=ic(15)+1
      iend=ic(16)-1
      k=12
      do 65 ii=iend,ibg,-1
          k=k-1
          lmin(k:k)=raw(ii:ii)
65    continue 
      if(lmin(6:6).eq.'-') lmin(5:6)='-0'
      if(lmin(6:6).eq.' ') lmin(6:6)='0'
      ii=ic(16)
70    ii=ii+1
      if(raw(ii:ii).ne.' ') go to 70
      iend=ii-1
      ibg=ic(16)+1
      if(ibg.gt.iend) go to 100
      k=12
      do 75 ii=iend,ibg,-1
      k=k-1
      lstd(k:k)=raw(ii:ii)
      if(lstd(6:6).eq.'-') lstd(5:6)='-0'
      if(lstd(6:6).eq.' ') lstd(6:6)='0'
75    continue      
100   continue
      write(6,9900)astid,date,cusip,ticker,contr,loanty,coll,tickets,units,value,age,lavg,lmax,lmin,lstd
      write(99,9900)astid,date,cusip,ticker,contr,loanty,coll,tickets,units,value,age,lavg,lmax,lmin,lstd
9900  format(1x,a8,1x,a8,1x,a9,1x,a6,3(1x,a1),1x,a6,1x,a14,1x,a14,5(1x,a11))      
!      if(i.lt.10000) go to 1
      go to 1
500   continue      
      stop

    end program clean_fees
